#ifndef USART_HPP
#define USART_HPP

#include "SerialPort.hpp"

namespace CH32V30X {

class SerialPort : public ::SerialPort {
public:
    enum class Method {
        Polling,
        Interrupt,
        DMA,
    };
public:
    virtual ~SerialPort() = 0;
    virtual bool open(void) = 0;
    virtual bool close(void) = 0;
    virtual int read(void *buffer,int size) = 0;
    virtual int write(void *buffer,int size) = 0;
    virtual int available(void) = 0;

    virtual bool setBaudrate(int baudrate) = 0;
    virtual int getBaudrate(void) = 0;
    virtual bool setWordLength(int word_length) = 0;
    virtual int getWordLength(void) = 0;
    virtual bool setParity(Parity parity) = 0;
    virtual Parity getParity(void) = 0;
    virtual bool setStopBits(StopBits stop_bits) = 0;
    virtual StopBits getStopBits(void) = 0;
    virtual bool setFlowControl(FlowControl flow_control) = 0;
    virtual FlowControl getFlowControl(void) = 0;

    virtual bool setTxMethod(Method method) = 0;
    virtual Method getTxMethod(void) = 0;
    virtual bool setRxMethod(Method method) = 0;
    virtual Method getRxMethod(void) = 0;

    virtual bool setBindedPins(int group) = 0;
    virtual int getBindedPins(void) = 0;

    virtual bool registEvent(EventType event_type,EventCallback callback) = 0;
    virtual bool unregistEvent(EventType event_type) = 0;

    static ::SerialPort *getInstance(int serialport_number);
    static bool freeInstance(::SerialPort *instance);
protected:
    Method tx_method;
    Method rx_method;
};

}

#endif
